<?php

namespace Home\Controller;

use Think\Controller;

class IndexController extends CommnController
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     *获取工单数量
     */
    public function get_order_num(){

        $where=[];
        $where['status']=array('in',array(1,2));
        $where['accept_apart_id']=$_SESSION['part_id'];
        $count=M('work_order','','KEFU')->where($where)->count();
        $this->ajaxReturn(array('code'=>'1001','count'=>$count));
    }
    /**
     *后台主页
     */
    public function index()
    {
//        var_dump(I('get.res'));return;
//        var_dump($_SESSION);
        $where = [];
        $where['status'] = array('eq', '1');
        $feedbackModel = M('user_feedback', '', 'KEFU');
        $tol = $feedbackModel->where($where)->count();
        if ($tol <= 0) {
            $tol = '';
        }
        if($_SESSION['role_id']=='3'){
            $top_power = M('power', '', 'KEFU')->WHERE("level=1 and status=1")->ORDER("weight asc")->SELECT();
            $next_power = M('power', '', 'KEFU')->WHERE("level=2 and status=1")->ORDER("weight asc")->SELECT();
        }else{
            $info = M('role', '', 'KEFU');
            $role = $info->WHERE(['id' => $_SESSION['role_id']])->FIND();
            $top_power = M('power', '', 'KEFU')->WHERE("id in({$role['top_id']}) and level=1 and status=1")->ORDER("weight asc")->SELECT();
            $next_power = M('power', '', 'KEFU')->WHERE("id in({$role['next_id']}) and level=2 and status=1")->ORDER("weight asc")->SELECT();
        }

        $w=[];
        $w['status']=1;
        $w['agent_status']=1;
        $is_showphonebar=M('admin','','KEFU')->where(['id'=>$_SESSION['id']])->field('status,agent_status')->find();
        $show='2';

       if($is_showphonebar['status']=='1' && $is_showphonebar['agent_status']=='1' ){
           $show='1';
       }

        $this->assign(array(
            'top_power' => $top_power,
            'next_power' => $next_power,
            'unresolve' => $tol,
            'show' => $show,
            'rid' => $_SESSION['role_id'],
        ));

        $this->m_username = $_SESSION['name'];
        $this->m_str = $_SESSION['login_time'];
        $this->rid = $_SESSION['role_id'];
        $this->display();
    }

    /**
     * 公告列表
     */
    /*  public function home(){

          $notice_db =M('notice','','KEFU');
          $tol =$notice_db->count();
          $row = '12';
          $page = new PageController($tol, $row);
          $fpage = $page->fpage();

          $notice=I('get.notice');
          if(!empty($notice)){
               $where=[];
               $where['b.title']=array('like','%'.$notice.'%');
                $field='';
  //            $notice=$notice_db->join('b join dxd_kefu.apart a on b.apart_id=a.id')->order('b.ctime desc')->where($where)->LIMIT($page->listfirst, $page->listRows)->select();
              $notice=$notice_db->order('b.ctime desc')->where($where)->LIMIT($page->listfirst, $page->listRows)->select();
              $tol =count($notice);
          }else{
  //            $notice=$notice_db->join('b join dxd_kefu.apart a on b.apart_id=a.id')->order('ctime desc')->LIMIT($page->listfirst, $page->listRows)->select();
              $notice=$notice_db->order('ctime desc')->LIMIT($page->listfirst, $page->listRows)->select();
          }

         foreach ($notice as $k=>$v){
             $part_name=M('apart','','KEFU')->where(['id'=>$v['apart_id']])->getfield('name');
             $notice[$k]['apart_id']=$part_name;
             $notice[$k]['ctime']=date('Y-m-d H:i',$v['ctime']);
         }
          $this->assign(array(
              'notice' => $notice,
              'fpage' => $fpage,
              'tol' => $tol
          ));
          $this->display();

      }*/

    public function home_details($id)
    {
        $notice = M('notice', '', 'KEFU')->where(['id' => $id])->find();
        $part_name = M('apart', '', 'KEFU')->where(['id' => $notice['apart_id']])->getfield('name');
        $time = date('Y-m-d H:i', $notice['ctime']);
        $this->assign(array(
            'part' => $part_name,
            'title' => $notice['title'],
            'content' => $notice['content'],
            'time' => $time
        ));
        $this->display();
    }

    /**
     * 统计图表（统计每个月和季度的新增人数、借款金额、还款金额）->用两个双环的圆形图（外层是每个月，内层是季度）
     */
    public function month_quarter()
    {
        $info = M('user', '', 'USER');
        $borrow = M('user_borrow', '', 'CAIWU');
        $repayment = M('user_repayment', '', 'CAIWU');

        $year = date('Y', time());
        $month = array('1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'); //月
        $quarter = array('第一季度', '第二季度', '第三季度', '第四季度'); //季度
        $add_user = array(); //每月新增人数
        $borrow_money = array(); //每月金额金额
        $repayment_money = array(); //每月还款金额
        $q_add_user = array(); //每季度新增人数
        $q_borrow_money = array(); //每季度金额金额
        $q_repayment_money = array(); //每季度还款金额

        //每个月新增人数
        for ($i = 1; $i <= 12; $i++) {
            $t = date('t', strtotime("{$year}-{$i}-1")); //获取指定月份的总天数
            $time = array(strtotime("{$year}-{$i}-1"), strtotime("{$year}-{$i}-{$t} 23:59:59"));
            $add_user_where['ctime'] = array('between', $time);
            $add_user[] = $info->WHERE($add_user_where)->COUNT();
        }

        //每个月借款金额
        for ($i = 1; $i <= 12; $i++) {
            $t = date('t', strtotime("{$year}-{$i}-1")); //获取指定月份的总天数
            $time = array(strtotime("{$year}-{$i}-1"), strtotime("{$year}-{$i}-{$t} 23:59:59"));
            $borrow_where['ctime'] = array('between', $time);
            $borrow_where['is_success'] = array('eq', '2');
            $borrow_m = $borrow->WHERE($borrow_where)->SUM("money");
            $borrow_money[] = !empty($borrow_m) ? $borrow_m : '0';
        }

        //每个月还款金额
        for ($i = 1; $i <= 12; $i++) {
            $t = date('t', strtotime("{$year}-{$i}-1")); //获取指定月份的总天数
            $time = array(strtotime("{$year}-{$i}-1"), strtotime("{$year}-{$i}-{$t} 23:59:59"));
            $repayment_where['real_time'] = array('between', $time);
            $repayment_where['status'] = array('eq', '3');
            $repayment_m = $repayment->WHERE($repayment_where)->SUM('repay_money');
            $repayment_money[] = !empty($repayment_m) ? $repayment_m : '0';
        }

        //每个季度新增人数
        for ($i = 1; $i <= 12; $i = $i + 3) {
            $j = $i + 2;
            $t = date('t', strtotime("{$year}-{$i}-1")); //获取指定月份的总天数
            $time = array(strtotime("{$year}-{$i}-1"), strtotime("{$year}-{$j}-{$t} 23:59:59"));
            $q_add_user_where['ctime'] = array('between', $time);
            $q_add_user[] = $info->WHERE($q_add_user_where)->COUNT();
        }

        //每个季度借款金额
        for ($i = 1; $i <= 12; $i = $i + 3) {
            $j = $i + 2;
            $t = date('t', strtotime("{$year}-{$i}-1")); //获取指定月份的总天数
            $time = array(strtotime("{$year}-{$i}-1"), strtotime("{$year}-{$j}-{$t} 23:59:59"));
            $q_borrow_where['ctime'] = array('between', $time);
            $q_borrow_where['is_success'] = array('eq', '2');
            $q_borrow_m = $borrow->WHERE($q_borrow_where)->SUM('money');
            $q_borrow_money[] = !empty($q_borrow_m) ? $q_borrow_m : '0';
        }

        //每个季度还款金额
        for ($i = 1; $i <= 12; $i = $i + 3) {
            $j = $i + 2;
            $t = date('t', strtotime("{$year}-{$i}-1")); //获取指定月份的总天数
            $time = array(strtotime("{$year}-{$i}-1"), strtotime("{$year}-{$j}-{$t} 23:59:59"));
            $q_repayment_where['real_time'] = array('between', $time);
            $q_repayment_where['status'] = array('eq', '3');
            $q_repayment_m = $repayment->WHERE($q_repayment_where)->SUM('repay_money');
            $q_repayment_money[] = !empty($q_repayment_m) ? $q_repayment_m : '0';
        }

        $this->assign(array(
            'month' => json_encode($month),
            'quarter' => json_encode($quarter),
            'add_user' => json_encode($add_user),
            'borrow_money' => json_encode($borrow_money),
            'repayment_money' => json_encode($repayment_money),
            'q_add_user' => json_encode($q_add_user),
            'q_borrow_money' => json_encode($q_borrow_money),
            'q_repayment_money' => json_encode($q_repayment_money)
        ));
        $this->display();
    }

    /**
     * 全国分布图
     */
    public function country()
    {
        $info = M('user', '', 'USER');
        $borrow_info = M('user_borrow', '', 'CAIWU');
        $repayment_info = M('user_repayment', '', 'CAIWU');

        //用户分布图
        $user['beijing'] = $info->WHERE(['province' => ['like', ['北京%']]])->COUNT();
        $user['tianjin'] = $info->WHERE(['province' => ['like', ['天津%']]])->COUNT();
        $user['shanghai'] = $info->WHERE(['province' => ['like', ['上海%']]])->COUNT();
        $user['chongqing'] = $info->WHERE(['province' => ['like', ['重庆%']]])->COUNT();
        $user['hebei'] = $info->WHERE(['province' => ['like', ['河北%']]])->COUNT();
        $user['henan'] = $info->WHERE(['province' => ['like', ['河南%']]])->COUNT();
        $user['yunnan'] = $info->WHERE(['province' => ['like', ['云南%']]])->COUNT();
        $user['liaoning'] = $info->WHERE(['province' => ['like', ['辽宁%']]])->COUNT();
        $user['heilongjiang'] = $info->WHERE(['province' => ['like', ['黑龙江%']]])->COUNT();
        $user['hunan'] = $info->WHERE(['province' => ['like', ['湖南%']]])->COUNT();
        $user['anhui'] = $info->WHERE(['province' => ['like', ['安徽%']]])->COUNT();
        $user['shandong'] = $info->WHERE(['province' => ['like', ['山东%']]])->COUNT();
        $user['xinjiang'] = $info->WHERE(['province' => ['like', ['新疆%']]])->COUNT();
        $user['jiangsu'] = $info->WHERE(['province' => ['like', ['江苏%']]])->COUNT();
        $user['zhejiang'] = $info->WHERE(['province' => ['like', ['浙江%']]])->COUNT();
        $user['jiangxi'] = $info->WHERE(['province' => ['like', ['江西%']]])->COUNT();
        $user['hubei'] = $info->WHERE(['province' => ['like', ['湖北%']]])->COUNT();
        $user['guangxi'] = $info->WHERE(['province' => ['like', ['广西%']]])->COUNT();
        $user['gansu'] = $info->WHERE(['province' => ['like', ['甘肃%']]])->COUNT();
        $user['shanxi'] = $info->WHERE(['province' => ['like', ['山西%']]])->COUNT();
        $user['neimenggu'] = $info->WHERE(['province' => ['like', ['内蒙古%']]])->COUNT();
        $user['shanxi'] = $info->WHERE(['province' => ['like', ['山西%']]])->COUNT();
        $user['jilin'] = $info->WHERE(['province' => ['like', ['吉林%']]])->COUNT();
        $user['fujian'] = $info->WHERE(['province' => ['like', ['福建%']]])->COUNT();
        $user['guizhou'] = $info->WHERE(['province' => ['like', ['贵州%']]])->COUNT();
        $user['guangdong'] = $info->WHERE(['province' => ['like', ['广东%']]])->COUNT();
        $user['qinghai'] = $info->WHERE(['province' => ['like', ['青海%']]])->COUNT();
        $user['xizang'] = $info->WHERE(['province' => ['like', ['西藏%']]])->COUNT();
        $user['sichuan'] = $info->WHERE(['province' => ['like', ['四川%']]])->COUNT();
        $user['ningxia'] = $info->WHERE(['province' => ['like', ['宁夏%']]])->COUNT();
        $user['hainan'] = $info->WHERE(['province' => ['like', ['海南%']]])->COUNT();
        $user['taiwan'] = $info->WHERE(['province' => ['like', ['台湾%']]])->COUNT();
        $user['xianggang'] = $info->WHERE(['province' => ['like', ['香港%']]])->COUNT();
        $user['aomen'] = $info->WHERE(['province' => ['like', ['澳门%']]])->COUNT();

        //全国借款分布图
        $borrow['beijing'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['北京%']], 'b.is_success' => '2'])->SUM("b.money");
        $borrow['tianjin'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['天津%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['shanghai'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['上海%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['chongqing'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['重庆%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['hebei'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['河北%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['henan'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['河南%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['yunnan'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['云南%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['liaoning'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['辽宁%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['heilongjiang'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['黑龙江%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['hunan'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['湖南%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['anhui'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['安徽%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['shandong'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['山东%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['xinjiang'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['新疆%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['jiangsu'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['江苏%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['zhejiang'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['浙江%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['jiangxi'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['江西%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['hubei'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['湖北%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['guangxi'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['广西%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['gansu'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['甘肃%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['shanxi'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['山西%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['neimenggu'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['内蒙古%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['shanxi'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['山西%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['jilin'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['吉林%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['fujian'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['福建%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['guizhou'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['贵州%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['guangdong'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['广东%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['qinghai'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['青海%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['xizang'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['西藏%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['sichuan'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['四川%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['ningxia'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['宁夏%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['hainan'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['海南%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['taiwan'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['台湾%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['xianggang'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['香港%']], 'b.is_success' => '2'])->SUM('b.money');
        $borrow['aomen'] = $borrow_info->JOIN("b JOIN dxd_user.user u ON b.vid=u.vid")->WHERE(['u.province' => ['like', ['澳门%']], 'b.is_success' => '2'])->SUM('b.money');

        //全国还款分布图
        $repayment['beijing'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['北京%']], 'r.status' => '3'])->SUM("r.repay_money");
        $repayment['tianjin'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['天津%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['shanghai'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['上海%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['chongqing'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['重庆%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['hebei'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['河北%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['henan'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['河南%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['yunnan'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['云南%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['liaoning'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['辽宁%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['heilongjiang'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['黑龙江%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['hunan'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['湖南%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['anhui'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['安徽%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['shandong'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['山东%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['xinjiang'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['新疆%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['jiangsu'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['江苏%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['zhejiang'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['浙江%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['jiangxi'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['江西%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['hubei'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['湖北%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['guangxi'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['广西%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['gansu'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['甘肃%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['shanxi'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['山西%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['neimenggu'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['内蒙古%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['shanxi'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['山西%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['jilin'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['吉林%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['fujian'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['福建%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['guizhou'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['贵州%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['guangdong'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['广东%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['qinghai'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['青海%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['xizang'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['西藏%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['sichuan'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['四川%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['ningxia'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['宁夏%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['hainan'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['海南%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['taiwan'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['台湾%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['xianggang'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['香港%']], 'r.status' => '3'])->SUM('r.repay_money');
        $repayment['aomen'] = $repayment_info->JOIN("r JOIN dxd_user.user u ON r.vid=u.vid")->WHERE(['u.province' => ['like', ['澳门%']], 'r.status' => '3'])->SUM('r.money');

        foreach ($borrow as $k => $v) {
            $borrow[$k] = !empty($v) ? $v : '0';
        }
        foreach ($repayment as $k => $v) {
            $repayment[$k] = !empty($v) ? $v : '0';
        }
        $max = max($user) + max($borrow) + max($repayment);
        $max_user = max($user);
        $max_borrow = max($borrow);
        $max_repay = max($repayment);
        $this->assign([
            'user' => json_encode($user),
            'borrow' => json_encode($borrow),
            'repayment' => json_encode($repayment),
            'max_user' => $max_user,
            'max_borrow' => $max_borrow,
            'max_repay' => $max_repay,
            'max' => $max
        ]);
        $this->display();
    }

}